//
//  FirstPatientInfoVC.m
//  Doctor
//
//  Created by 阳光 on 16/9/7.
//  Copyright © 2016年 阳光. All rights reserved.
//  初诊病例详情界面

#import "FirstPatientInfoVC.h"

#import "PatientInfoCell.h"
#import "PatientBaseInfoCell.h"
#import "PatientHealthInfoCell.h"
#import "PatientBabyInfoCell.h"
#import "PatientOtherInfoCell.h"

static NSString *patientInfoCellIdentifier=@"PatientInfoCellIdentifier";
static NSString *patientBaseInfoCellIdentifier=@"PatientBaseInfoCellIdentifier";
static NSString *patientHealthInfoCellIdentifier=@"PatientHealthInfoCellIdentifier";
static NSString *patientBabyInfoCellIdentifier=@"PatientBabyInfoCellIdentifier";
static NSString *patientOtherInfoCellIdentifier=@"PatientOtherInfoCellIdentifier";

@interface FirstPatientInfoVC ()<UITableViewDataSource,UITableViewDelegate>

// 病例
@property(nonatomic,strong)UITableView *patientInfoTableView;

@end



@implementation FirstPatientInfoVC

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.title = NSLocalizedString(@"Patient Case", nil);//@"病例详情";
    
    [self initNavBarBtnItem];
    
    [self initTableView];
    
}

-(void)initTableView
{
    // _patientInfoTableView
    _patientInfoTableView=[[UITableView alloc]initWithFrame:CGRectMake(0,1,APPW,APPH-64) style:UITableViewStylePlain];
    _patientInfoTableView.delegate=self;
    _patientInfoTableView.dataSource=self;
    _patientInfoTableView.showsVerticalScrollIndicator=NO;
    _patientInfoTableView.backgroundColor=MAIN_BACK_COLOR;
    _patientInfoTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_patientInfoTableView];
    [_patientInfoTableView registerClass:[PatientInfoCell class] forCellReuseIdentifier:patientInfoCellIdentifier];
    [_patientInfoTableView registerClass:[PatientBaseInfoCell class] forCellReuseIdentifier:patientBaseInfoCellIdentifier];
    [_patientInfoTableView registerClass:[PatientHealthInfoCell class] forCellReuseIdentifier:patientHealthInfoCellIdentifier];
    [_patientInfoTableView registerClass:[PatientBabyInfoCell class] forCellReuseIdentifier:patientBabyInfoCellIdentifier];
    [_patientInfoTableView registerClass:[PatientOtherInfoCell class] forCellReuseIdentifier:patientOtherInfoCellIdentifier];
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0)
    {
        PatientInfoCell *cell=[tableView dequeueReusableCellWithIdentifier:patientInfoCellIdentifier];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;
    }
    else  if (indexPath.section==1)
    {
        PatientBaseInfoCell *cell=[tableView dequeueReusableCellWithIdentifier:patientBaseInfoCellIdentifier];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;
    }
    else if (indexPath.section==2)
    {
        PatientHealthInfoCell *cell=[tableView dequeueReusableCellWithIdentifier:patientHealthInfoCellIdentifier];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;
    }
    else if (indexPath.section==3)
    {
        PatientBabyInfoCell *cell=[tableView dequeueReusableCellWithIdentifier:patientBabyInfoCellIdentifier];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;
    }
    else
    {
        PatientOtherInfoCell *cell=[tableView dequeueReusableCellWithIdentifier:patientOtherInfoCellIdentifier];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        return cell;
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
        if (indexPath.section==0)
        {
            return 50;
        }
        else  if (indexPath.section==1)
        {
            return 44*7;
        }
        else if (indexPath.section==2)
        {
            return 44*9;
        }
        else
        {
            return 44*4;
        }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section==1||section==2||section==3||section==4)
    {
        return 45;
    }
    else
    {
        return 0.000000;
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
        if (section==1)
        {
            UIView *headView=[UIView new];
            headView.backgroundColor=MAIN_BACK_COLOR;
            
            UILabel *userLabel=[headView getLabelWithText:NSLocalizedString(@"Basic Information", nil) font:Font_Number(16) textColor:Color666666 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];//基本信息;
            [headView addSubview:userLabel];
            [userLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.top.mas_equalTo(kmargin);
            }];
            return headView;
        }
        else if (section==2)
        {
            UIView *headView=[UIView new];
            headView.backgroundColor=MAIN_BACK_COLOR;
            
            UILabel *userLabel=[headView getLabelWithText:NSLocalizedString(@"Physical Condition", nil) font:Font_Number(16) textColor:Color666666 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
            [headView addSubview:userLabel];
            [userLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.top.mas_equalTo(kmargin);
            }];
            return headView;
        }
        else if (section==3)
        {
            UIView *headView=[UIView new];
            headView.backgroundColor=MAIN_BACK_COLOR;
            
            UILabel *userLabel=[headView getLabelWithText:NSLocalizedString(@"Fertility History", nil) font:Font_Number(16) textColor:Color666666 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
            [headView addSubview:userLabel];
            [userLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.top.mas_equalTo(kmargin);
            }];
            return headView;
        }
        else
        {
            UIView *headView=[UIView new];
            headView.backgroundColor=MAIN_BACK_COLOR;
            
            UILabel *userLabel=[headView getLabelWithText:NSLocalizedString(@"Others", nil) font:Font_Number(16) textColor:Color666666 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
            [headView addSubview:userLabel];
            [userLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.top.mas_equalTo(kmargin);
            }];
            return headView;
        }
}

// 禁止tableview滑动时header不悬浮
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat sectionHeaderHeight=45;
    if(scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0)
    {
        scrollView.contentInset=UIEdgeInsetsMake(-scrollView.contentOffset.y,0,0,0);
    }
    else if (scrollView.contentOffset.y>=sectionHeaderHeight)
    {
        scrollView.contentInset=UIEdgeInsetsMake(-sectionHeaderHeight,0,0,0);
    }
}


-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section==4)
    {
        UIView *footView=[UIView new];
        return footView;
    }
    else
    {
        return nil;
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section==4)
    {
        return kmargin*3;
    }
    else
    {
        return 0.00000;
    }
}

-(void)initNavBarBtnItem
{
    self.navigationItem.leftBarButtonItem=[UIBarButtonItem initWithNormalImage:@"back_gray" target:self action:@selector(backItemEvent)];
}

-(void)backItemEvent
{
    [self.navigationController popViewControllerAnimated:NO];
}


@end



